<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib  uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib  uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="${pageContext.request.contextPath}/bootstrap/css/bootstrap.min.css" />
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-2.2.3.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/user-info.js"></script>
<title>用户列表</title>
<script type="text/javascript">
	// 条件查询
	function findUser(){
		var realName = $("#realName").val();
		var age = $("#age").val();
		var nz_number = /^\+?[1-9][0-9]*$/;
		if (age != '' && !nz_number.test(age)) {
			alert("年龄必须为非零正整数");
			return;
		}
		$("#userForm").submit();
	}
	
	// 分页查询
	function userPage(page) {
		$("#pageNo").val(page);
		findUser();
	}
	
	function forwardExcel(){
		window.location="${pageContext.request.contextPath}/system/uploadUserExcelData.jsp";
	}
	
	function delUsers(path){
		var params="";
		//获取所有的选中的多选框
		 var oInputs=$("input[type='checkbox']:checked");
		 if(oInputs.length<1){
			 alert("您还没有选中记录！");
		 }else{
			 //获取所有选中的多选择的值，拼组成id=1,2,3..格式 
			 
			 $.each(oInputs,function(index,element){
				 params+=$(element).val()+",";
			 });
			 params=params.substring(0, params.length-1);
			 $.ajax({
				 url:path+"/userInfo/delbatch/user",
				 method:"POST",
				 data:"paramsIds="+params,
				 cache:false,
				 dataType:"json",
				 success:function(data){
					 if(data.code=="200"){
						 alert(data.message);
						 window.location=path+"/userInfo/find/user/list";
					 }else if(data.code=="400"){
						 alert(data.message);
					 }
				 }
			 });
			 
		 }
		 
	}
</script>
</head>
<body>
<div class="container" style="width: 100%;padding: 25px 15px;">
	<div class="row clearfix">
		<div class="col-md-12 column" style="padding: 20px;">
			<div style="float: left;">
				
						<input type="button" class="btn btn-primary btn" value="添加" onclick="javascript:location.href='${pageContext.request.contextPath}/userInfo/add/user/page.action'"/>
					
					
						<input type="button" class="btn btn-primary btn" onclick="forwardExcel();" value="导入用户信息">
					
						<input type="button" class="btn btn-primary btn" onclick="delUsers('${pageContext.request.contextPath}');" value="批量删除">
					
				
			</div>
			<form action="${pageContext.request.contextPath}/userInfo/find/user/list.action" method="post" id="userForm" role="form" class="form-inline" style="float: right;margin-bottom: 10px;">
				<div class="form-group" style="margin-right: 20px;">
					 <label for="exampleInputEmail1" style="margin-right: 10px;">姓名</label><input type="text" class="form-control" id="realName" name="realName" placeholder="姓名"/>
				</div>
				<div class="form-group">
					 <label for="exampleInputPassword1" style="margin-right: 10px;">年龄</label><input type="text" class="form-control" id="age" name="age" placeholder="年龄"/>
				</div>
				<input type="hidden" id="pageNo" name="offset" value="">
				<button type="button" class="btn btn-primary btn" onclick="findUser()">查询</button>
			</form>
			<table class="table table-bordered" style="margin-top: 20px;">
				<thead>
					<tr>
						<th style="width: 50px;text-align: center;">选择</th>
						<th>用户名</th>
						<th style="width: 100px;">年龄</th>
						<th style="width: 100px;">性别</th>
						<th>手机号</th>
						<th>邮箱</th>
						<th>生日</th>
						<th>入职日期</th>
						<th style="width: 100px;">状态</th>
						<th style="width: 200px;">操作</th>
					</tr>
				</thead>
				<tbody>
					
						<tr class="success">
						  <c:forEach var="userInfo" items="${pageView.records}">
								<tr>
								<td style="width: 50px;text-align: center;"><input type="checkbox" name="id" value="${userInfo.id}"/></td>
								<td>${userInfo.realName}</td>
								<td>${userInfo.age}</td>
								<td>${userInfo.sex == 0 ? "男" : userInfo.sex == 1 ? "女" : "未知" }</td>
								<td>${userInfo.mobile}</td>
								<td>${userInfo.email}</td>
								<td>${userInfo.birthday}</td>
								<td><fmt:formatDate value="${userInfo.entryTime}" pattern="yyyy-MM-dd"/></td>
								<td>${userInfo.status == 0 ? "试用期" : userInfo.status == 1 ? "转正" : "离职" }</td>
								<td>
									      <a href="${pageContext.request.contextPath}/userInfo/detail/user.action?id=${userInfo.id }&method=detail" class="btn btn-primary btn">详情</a>
									
										  <a href="${pageContext.request.contextPath}/userInfo/detail/user.action?id=${userInfo.id }&method=update" class="btn btn-primary btn">修改</a>
										
										  <a href="javascript:void(0);" onclick="userDel('${pageContext.request.contextPath}', '${userInfo.id}')" class="btn btn-primary btn">删除</a>
										
								 </td>
							 </tr>
						</c:forEach>	
						
						
				</tbody>
			</table>
			<span>共${pageView.totalRecord}条记录 共${pageView.totalPage}页 当前第${pageView.currentPage}页</span>
			<!-- 分页 -->
			<ul class="pagination" style="float: right;margin: 0;">
				<li><a href="javascript:void(0)" onclick="userPage(1)">首页</a></li>
				<c:choose>
					<c:when test="${pageView.currentPage!=1}">
						<li><a href="javascript:void(0)" onclick="userPage('${pageView.currentPage-1}')">上一页</a></li>
					</c:when>
					<c:otherwise>
						<li class="disabled"><a href="javascript:void(0)">上一页</a></li>
					</c:otherwise>
				</c:choose>
				<c:choose>
					<c:when test="${pageView.currentPage != pageView.totalPage}">
						<li><a href="javascript:void(0)" onclick="userPage('${pageView.currentPage+1}')">下一页</a></li>
					</c:when>
					<c:otherwise>
						<li class="disabled"><a href="javascript:void(0)">下一页</a></li>
					</c:otherwise>
				</c:choose>
				<li><a href="javascript:void(0)" onclick="userPage('${pageView.totalPage}')">尾页</a></li>
			</ul>
		</div>
	</div>
</div>

</body>
</html>